package com.example.jegotrip.utils;

import static com.example.jegotrip.R.*;

import android.annotation.SuppressLint;
import android.content.Context;
import android.content.res.Resources;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.animation.AnimationUtils;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.example.jegotrip.R;

import java.util.Objects;

public class CustomToast {
    public static void showCenterToast(Context context, String message) {
        LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        View layout = inflater.inflate(R.layout.toast_layout, null);
        ImageView iv_cover = layout.findViewById(R.id.iv_cover);
        TextView toastMessage = layout.findViewById(R.id.toast_message);
        toastMessage.setText(message);
        Toast toast = new Toast(context);
        toast.setGravity(Gravity.CENTER, 0, 0); // 设置居中显示
        toast.setDuration(Toast.LENGTH_SHORT);
        toast.setView(layout);
        Objects.requireNonNull(toast.getView()).setAnimation(AnimationUtils.loadAnimation(context, R.anim.slide_in));
        toast.show();
    }
}
